package com.levine.base_libs.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;

import com.levine.base.R;
import com.levine.base_libs.view.PopupWd;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;

public class MyDialog {
    public static QMUITipDialog showQmuiDialog(Context context, String text, int iconType) {
        QMUITipDialog qmuiDialog = createQmuiDialog(context, text, iconType);
        qmuiDialog.show();
        return qmuiDialog;
    }

    public static QMUITipDialog showQmuiDialog(Context context, String text, int iconType, boolean cancelable) {
        QMUITipDialog qmuiDialog = createQmuiDialog(context, text, iconType);
        qmuiDialog.setCancelable(cancelable);
        qmuiDialog.show();
        return qmuiDialog;
    }

    public static QMUITipDialog createQmuiDialog(Context context, String text, int iconType) {
        QMUITipDialog qmuiTipDialog = new QMUITipDialog.Builder(context)
                .setTipWord(text)
                .setIconType(iconType)
                .create();
        return qmuiTipDialog;
    }

    public static QMUITipDialog showQmuiDialogForDismiss(Activity activity, String text, int iconType, int dismissTime) {
        final QMUITipDialog qmuiDialog = createQmuiDialog(activity, text, iconType);
        qmuiDialog.show();
        activity.getWindow().getDecorView().postDelayed(new Runnable() {
            @Override
            public void run() {
                qmuiDialog.dismiss();
            }
        }, dismissTime);
        return qmuiDialog;
    }

    public static PopupWd createPopup(Context context, View showView, int width, int height) {
        PopupWd popupWd = new PopupWd(showView, width, height);
        popupWd.setFocusable(true);
        popupWd.setAnimationStyle(R.style.pw_details_fuwu);
        popupWd.setBackgroundDrawable(new ColorDrawable());
        popupWd.setDarkStyle(-1);//动画
        popupWd.setDarkColor(Color.parseColor("#a0000000"));//颜色
        popupWd.resetDarkPosition();
        return popupWd;
    }

    public static PopupWd showPopup(Activity activity, View showView, int width, int height, int gravity) {
        PopupWd popup = createPopup(activity, showView, width, height);
        popup.showAtLocation(activity.getWindow().getDecorView(), gravity, 0, 0);
        return popup;
    }


}
